//
//  AppBaseNaviController.swift
//  
//
//  Created by bo wang on 2021/3/3.
//  Copyright © 2021 wangbo. All rights reserved.
//

import UIKit

class AppBaseNaviController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
    }
    
    override var prefersStatusBarHidden: Bool { false }
    override var preferredStatusBarStyle: UIStatusBarStyle { .default }
    override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { .none }

    override var childForStatusBarHidden: UIViewController? {
        if let vc = visibleViewController, !vc.isBeingDismissed {
            return vc
        }
        return topViewController
    }
    override var childForStatusBarStyle: UIViewController? {
        if let vc = visibleViewController, !vc.isBeingDismissed {
            return vc
        }
        return topViewController
    }
    override var childForHomeIndicatorAutoHidden: UIViewController? {
        if let vc = visibleViewController, !vc.isBeingDismissed {
            return vc
        }
        return topViewController
    }
}

extension AppBaseNaviController: UIGestureRecognizerDelegate {
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if let vc = topViewController as? AppBaseVC, vc.disablePopGesture {
            return false
        }
        return viewControllers.count > 1
    }
}
